$(function () {

    init();
})

function init() {
    FastClick.attach(document.body);

    $("#reasonType").picker({
        title: "请选择失败原因",
        cols: [
            {
                textAlign: 'center',
                values: baseService.getServerConstNames("failReason")
            }
        ]
    });
    $("#resultType").picker({
        title: "请选择维修方式",
        cols: [
            {
                textAlign: 'center',
                values: baseService.getServerConstNames("repairType")
            }
        ]
    });
    $("input[name='checkbox1']").on("click", function () {
        var value = $("input[name='checkbox1']:checked").val();
        if (value == "1") {
            $("#resultTypeRow").show();
            $("#resonTypeRow").hide();
        } else {
            $("#resultTypeRow").hide();
            $("#resonTypeRow").show();
        }
    })
    $("#cancel").on("click", function () {
        myBack();
    });
    $("#submit").on("click", function () {
        $.confirm("确认提交", "确认将修理结果提交？", function () {
            var value = $("input[name='checkbox1']:checked").val();
            if (value == "1") {
                equipmemtService.saveRepairWorkResult({
                    equipmentId: eid,
                    result: "800001",
                    repairApplyId: id,
                    repairApplyState: "201601",
                    describe:$("#describe").val()
                }, function (data) {
                    if (data.success) {
                        baseService.myBack();
                    } else {
                        $.alert(data.errorMsg);
                    }
                });
            } else {
                $.confirm("确认失败？", "确认", function () {
                    equipmemtService.saveRepairWorkResult({
                        equipmentId: eid,
                        result: "800002",
                        repairApplyId: id,
                        repairApplyState: "201801",
                        describe:$("#describe").val()
                    }, function (data) {
                        if (data.success) {
                            baseService.myBack();
                        } else {
                            $.alert(data.errorMsg);
                        }
                    });
                })
            }

        });
    })
}